package com.lzy.shops.service.impl;

import com.lzy.shops.bean.User;
import com.lzy.shops.mapper.UserMapper;
import com.lzy.shops.service.UserService;
import com.lzy.shops.utils.ResponseData;
import com.lzy.shops.utils.exception.ExistException;
import javafx.scene.input.DataFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Integer registerUser(User user) throws ExistException {
        User userInfo = userMapper.findByUser(user);
        if(userInfo == null){
            user.setLast_login_time(user.getRegister_time());
            return userMapper.registerUser(user);
        }else{
            throw new ExistException("用户已存在");
        }
    }

    @Override
    public User findByUser(User user) {
        return userMapper.findByUser(user);
    }

    @Override
    public Integer updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public Integer deleteUser(Integer id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public Integer updatePassword(User user) {
        return userMapper.updatePassword(user);
    }

    @Override
    public Integer loginUser(User user) {
        return userMapper.loginUser(user);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }
}
